package com.hsc.account;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class gridadapter extends BaseAdapter {

	private LayoutInflater layoutInflater;
	private List<Map<String, Object>> data_list=null;
	private int mday;
	private int imon;

	public gridadapter(Context context,List<Map<String, Object>> data_list,int imon,int mday)
	{
		this.data_list = data_list;
		layoutInflater = LayoutInflater.from(context);
		this.imon=imon;
		this.mday=mday;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data_list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;

		if (layoutInflater != null) {

			view = layoutInflater.inflate(R.layout.dateitem, null);
			LinearLayout line =  (LinearLayout) view.findViewById(R.id.mline);
			TextView mon = (TextView) view.findViewById(R.id.mon);
			TextView msum = (TextView) view.findViewById(R.id.msum);

			String date = data_list.get(position).get("text").toString();

			if(!date.equals(" "))
			{
				if(mday==Integer.parseInt(date))
				{
					line.setBackgroundColor(Color.GRAY);
					oneActivity.gv=position;
				}

				else if(mday==99)
				{
					Time time = new Time();
					time.setToNow();

//		 		        System.out.println(imon+" "+time.month+"  "+time.monthDay+" "+mday);
					if((time.month+1)==imon && time.monthDay==Integer.parseInt(date))
					{
						line.setBackgroundColor(Color.LTGRAY);
					}
				}else
				{
					line.setBackgroundColor(Color.WHITE);
				}
			}

			//获取自定义的类实例
			mon.setText(date);
			msum.setText(data_list.get(position).get("sum").toString());

//	            view.setOnClickListener(new OnClickListener() {
//					
//					@Override
//					public void onClick(View v) {
//						
//						
//					}
//				});

		}
		return view;
	}



}
